//
//  ViewController.m
//  TFY_Category
//
//  Created by 田风有 on 2019/5/23.
//  Copyright © 2019 恋机科技. All rights reserved.
//

#import "ViewController.h"
#import "TFY_CategoryHerder.h"
#import "HomeTableViewController.h"
@interface ViewController ()
@property(nonatomic , strong)UILabel *label;

@property(nonatomic , strong)UIButton *btn,*hengping;

@property(nonatomic , strong)UIImageView *imageView;

@property(nonatomic , strong)UIButton *time_btn;

@property(nonatomic , strong)UIView *back_View2;

@property(nonatomic , strong)TFY_CommonUtils *time;

@property(nonatomic, assign) NSInteger seconds;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor =[UIColor generateDynamicColor:[UIColor cyanColor].tfy_lighten darkColor:[UIColor cyanColor].tfy_darken];
    
    self.label.frame = CGRectMake(30, 64, [UIScreen mainScreen].bounds.size.width-60, 50);
    self.label.tfy_addToSuperView(self.view);
    
    self.btn.frame = CGRectMake(30, self.label.frame.origin.y+self.label.frame.size.height+20, [UIScreen mainScreen].bounds.size.width-60, 50);
    [self.view addSubview:self.btn];
    
    self.imageView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2-40, self.btn.frame.origin.y+self.btn.frame.size.height+20, 80, 80);
    [self.view addSubview:self.imageView];
    
    self.time_btn.frame = CGRectMake(50, self.imageView.frame.size.height+self.imageView.frame.origin.y+20, [UIScreen mainScreen].bounds.size.width-100, 100);
    [self.view addSubview:self.time_btn];
    
    self.back_View2.frame = CGRectMake(50, self.time_btn.frame.origin.y+self.time_btn.frame.size.height+20, [UIScreen mainScreen].bounds.size.width-100, 100);
    [self.view addSubview:self.back_View2];
    
    NSString *hhhhhhh = [@"170CM" removeLastSubString:@"CM"];
     
    self.label.tfy_text(hhhhhhh);
    
    NSDictionary *titleDict = @{@"图片在上":@"hengping",@"图片在下":@"export",@"图片在左":@"Interpretation",@"图片在右":@"lover"};
    __block NSInteger i=0;
    [titleDict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        i++;
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(0+(i-1)*[UIScreen mainScreen].bounds.size.width/4, 20+self.back_View2.frame.origin.y+self.back_View2.frame.size.height, [UIScreen mainScreen].bounds.size.width/4, 80);
        [btn setTitle:key forState:UIControlStateNormal];
        [btn setTitleColor:UIColor.redColor forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:obj] forState:UIControlStateNormal];
        if (i==1) {
            btn.tfy_layouEdgeInsetsPosition(ButtonPositionImageTop_titleBottom, 15);
            btn.backgroundColor = [UIColor blueColor];
        }
        if (i==2) {
            
            btn.tfy_layouEdgeInsetsPosition(ButtonPositionImageBottom_titleTop, 15);
            btn.backgroundColor = [UIColor purpleColor];
        }
        if (i==3) {
            
            btn.tfy_layouEdgeInsetsPosition(ButtonPositionImageLeft_titleRight, 10);
            btn.backgroundColor = [UIColor orangeColor];
        }
        if (i==4) {
            btn.tfy_layouEdgeInsetsPosition(ButtonPositionImageRight_titleLeft, 10);
            btn.backgroundColor = [UIColor yellowColor];
        }
        [self.view addSubview:btn];
    }];
    
    
}

-(UILabel *)label{
    if (!_label) {
        _label = tfy_label().tfy_text(@"测试数据").tfy_textcolor(@"436FFF", 1).tfy_fontSize([UIFont systemFontOfSize:15]).tfy_backgroundColor(@"fafafa", 1).tfy_alignment(1);
        [_label addBorderWithColor:[UIColor generateDynamicColor:UIColor.redColor.tfy_lighten darkColor:UIColor.redColor.tfy_darken] BodrerWidth:4 direction:BorderDirectionTop|BorderDirectionBottom];
    }
    return _label;
}

-(UIButton *)btn{
    if (!_btn) {
        _btn = tfy_button().tfy_backgroundColor([UIColor purpleColor], 1).tfy_title(@"计时开始",UIControlStateNormal, @"ffffff",UIControlStateNormal, [UIFont boldSystemFontOfSize:16]).tfy_borders(4, @"ffffff").tfy_cornerRadius(20).tfy_action(self, @selector(btnClick:),UIControlEventTouchUpInside);
    }
    return _btn;
}


-(void)btnClick:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (btn.selected) {
        self.btn.tfy_backgroundColor(@"FFC301", 1).tfy_title(@"计时结束",UIControlStateNormal, @"ffffff",UIControlStateNormal, [UIFont boldSystemFontOfSize:16]);
        self.imageView.tfy_badgeValue = @"22";
        self.time = [[TFY_CommonUtils alloc] initWithInterval:1 repeats:YES queue:dispatch_get_main_queue() block:^{
            self.seconds++;
            self.time_btn.tfy_text([NSString stringWithFormat:@"%.2ld:%.2ld",self.seconds/60,self.seconds%60],UIControlStateNormal);
        }];
        
    }
    else{
        [self.time cancel];
        self.btn.tfy_backgroundColor(@"436FFF", 1).tfy_title(@"计时开始",UIControlStateNormal, @"ffffff",UIControlStateNormal, [UIFont boldSystemFontOfSize:16]);
        self.imageView.tfy_badgeValue = @"666";
        
    }
}

-(UIImageView *)imageView{
    if (!_imageView) {
        _imageView = tfy_imageView().tfy_imge(@"guanyucopy").tfy_cornerRadius(5).tfy_action(self,@selector(imageViewClick));
        _imageView.tfy_badgeValue = @"3";
        _imageView.tfy_badgeBGColor = [UIColor blackColor];
    }
    return _imageView;
}

-(UIButton *)time_btn{
    if (!_time_btn) {
        _time_btn = tfy_button();
        _time_btn.tfy_textcolor(@"436FFF",UIControlStateNormal).tfy_font([UIFont boldSystemFontOfSize:16]).tfy_text(@"00:00",UIControlStateNormal).tfy_alAlignment(1).tfy_backgroundColor(@"ffffff", 1);
        [_time_btn tfy_setShadow:CGSizeMake(0, 0) shadowOpacity:0.3 shadowRadius:5 shadowColor:[UIColor blackColor]];
        
    }
    return _time_btn;
}

-(UIView *)back_View2{
    if (!_back_View2) {
        _back_View2 = [UIView new];
        _back_View2.backgroundColor = [UIColor generateDynamicColor:[UIColor whiteColor].tfy_lighten darkColor:[UIColor whiteColor].tfy_darken];
        
        [_back_View2 addBorderWithColor:UIColor.orangeColor BodrerWidth:2 direction:BorderDirectionLeft|BorderDirectionRight];
        
        [_back_View2 clipWithType:CornerClipTypeBothTop radius:20];
    }
    return _back_View2;
}

-(void)imageViewClick{
    HomeTableViewController *home = [HomeTableViewController new];
    home.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:home animated:YES completion:nil];
}
@end
